/* Copyright (C) 2015-2016 HangZhou Zenzet Technology Co., Ltd.
 * All right reserved

 * File:crypto/locketcommon.h
 * Author:guojianchuan/max
 * Date:2016-06-02
 
 */

#ifndef _LOCKET_ERR_H_
#define _LOCKET_ERR_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Declare: Function */
char* LOCKET_ERR_GetString (void);

void* LOCKET_malloc (size_t size);

void LOCKET_free (void **p);
unsigned long long LOCKET_GetFileSize (char* pcPath);
FILE* LOCKET_OpenFile (char* pcPath, char* pcMode);
size_t LOCKET_ReadFile (void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t LOCKET_WriteFile (void *ptr, size_t size, size_t nmemb, FILE *stream);

/* Declare: Macro */
#define INVALID_FILE_SIZE   (unsigned long long)(-1)

/* 计算块数量 */
#define CALC_BLOCK_NUM(length, blocksize) (0 == length % blocksize) ? (length / blocksize) : (length / blocksize + 1)

#define CRYPT_ALGORITHM             "AES-128-CFB"

#define TAG_LEN                     6
#define HEADER_TAG_LEN              (TAG_LEN + 2)
#define META_TAG_LEN                TAG_LEN
#define THUMB_TAG_LEN               TAG_LEN
#define ENCRYPT_TAG_LEN             TAG_LEN

#define HEADER_PREFIX_TAG           {0x25, 0x5A, 0x5A, 0x4C, 0x4B, 0x54, 0x00, 0x00}
#define META_PREFIX_TAG             {0xFF, 0x4C, 0x4B, 0x54, 0x48, 0x00}
#define META_SUFFIX_TAG             {0xFF, 0x25, 0x25, 0x45, 0x4F, 0x48}
#define THUMB_PREFIX_TAG            {0xFF, 0x4C, 0x4B, 0x54, 0x54, 0x00}
#define THUMB_SUFFIX_TAG            {0xFF, 0x25, 0x25, 0x45, 0x4F, 0x54}
#define ENCRYPT_PREFIX_TAG          {0xFF, 0x4C, 0x4B, 0x54, 0x43, 0x00}
#define ENCRYPT_SUFFIX_TAG          {0xFF, 0x25, 0x25, 0x45, 0x4F, 0x46}

#define HEADERMETA_SIZE             1024
#define HEADER_SIZE                 8
#define META_LEN_SIZE               5
#define META_SIZE                   (HEADERMETA_SIZE - HEADER_SIZE - META_LEN_SIZE)

#define GET_PROGRESS(cur, total)    ((1.0 * cur) / (1.0 * total))


#ifdef __cplusplus
}
#endif

#endif  /* _LOCKET_AES_H_ */
